﻿#region 命名空间

using System;
using System.Linq;
using System.Web.UI;
using System.Web.UI.WebControls;
using WinnerCMS.Common;
using WinnerCMS.BLL;
using WinnerCMS.Model.Attribute;
using WinnerCMS.Model.Enum;

#endregion

namespace WinnerCMS.WebUI.Admin.Category
{
    [Access("256003")]
    public partial class Permission : Page
    {
        private readonly CategoryManage _myBll = new CategoryManage();

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                new ModelManage().BindDDL(this.ddlModel, "全部模型");
                Bind();
            }
        }

        private void Bind()
        {
            var modelId = byte.Parse(this.ddlModel.SelectedValue);
            if (modelId > 0)
            {
                this._myBll.BindDDL(this.lblCategory, BindOption.NoLink, null, modelId);
            }
            else
            {
                this._myBll.BindDDL(this.lblCategory, BindOption.NoLink, null, null);
            }
        }

        protected void btnOK_Click(object sender, EventArgs e)
        {
            var categoryIds =
                (from ListItem li in this.lblCategory.Items where li.Selected select li.Value.ToInt()).ToList();

            new RightsManage().DistributeCategoryToRole(categoryIds, int.Parse(Request["roleid"]));
        }

        protected void ddlModel_SelectedIndexChanged(object sender, EventArgs e)
        {
            Bind();
        }
    }
}